<html class="has-topbar has-bottombar">
<head>
	<meta charset="UTF-8">
	
	<title>交易大厅</title>
	<include file="Public:head" />
	<style>
		.table-list-deal dd {
			line-height: 35px;
		}
		.table-list-deal dd span{
			display: inline-block;
		}
	</style>
</head>
<body class="bgcolor">
<header class="mui-bar mui-bar-bg mui-bar-nav">
	<a class="mui-icon mui-icon-left-nav mui-pull-left" href="javascript:history.go(-1)"></a>
	<!-- <h1 class="mui-title color_white">{$coin_name}/{$coin_type}<i class="icons iconfont icon-ai-arrow-down"></i></h1>-->
</header>
<div class="mui-content">
	<div class="mui-bar-box mui-bar-bg" style="border-bottom:8px solid #1f2b3d;">
		<div class="cur-box">
			<div class="marketinfo">
				<div class="fl price-show">
					<h3 id="market_new_price" style="color:#fff;">--</h3>
					<span style="color:#a6a5a7;">≈ {$rmbprice} {$market_coin}</span>
				</div>
				<div class="fr float buy" id="market_change">--</div>
			</div>
		</div>
		<ul class="topinfo-bottom">
			<li><span class="htitle">{:L("最高")}</span><span class="hnum" id="market_max_price">--</span></li>
			<li><span class="htitle">{:L("最低")}</span><span class="hnum" id="market_min_price">--</span></li>
			<li><span class="htitle">{:L("总量")}</span><span class="hnum" id="market_volume">--</span></li>
		</ul>
	</div>
</div>

<div class="mui-content cur-padding-bottom bgcolor" style="margin-top: 50px;">
	<!--Candlestick chart-->
	<div id="kline" style="border-bottom:8px solid #1f2b3d;">
		<div id="paint_chart" style="width:100%;overflow:hidden;margin:0 auto;">
			<iframe style="border-style: none;" border="0" width="100%" height="350" id="market_chart" src="/Trade/specialty?market={$market}"></iframe>
		</div>
	</div>
	<!--Candlestick chart end-->
	
	<div class="cur-box trade_entrust" style="margin-top:0;background-color:#313e51;">{:L("买卖盘")}</div>
	<div class="cur-box">
		<div class="table-entrust" style="border-bottom: none;">
			<ul class="table-head">
				<li class="tl">{:L("买一价")}({$coin_type})</li>
				<li class="tc">{:L("数量")}({$coin_name})</li>
				<li class="tr">{:L("卖一价")}({$coin_type})</li>
			</ul>
			<div class="table-list">
				<dl class="fl coinlist-left" id="buylist"></dl>
				<dl class="fr coinlist-right" id="selllist"></dl>
			</div>
		</div>
	</div>
	
	<div class="cur-box trade_entrust" style="margin-top:0px;background-color:#313e51;">{:L("最新成交")}</div>
	<div class="cur-box">
		<div class="table-entrust" style="border-bottom: none;">
			<ul class="table-head">
				<li class="tl">{:L("时间")}</li>
				<li class="tc">{:L("成交价")}({$coin_type})</li>
				<li class="tr">{:L("数量")}({$coin_name})</li>
			</ul>
			<div class="table-list-deal" id="orderlist">
				{$orderlist}
			</div>
		</div>
	</div>
</div>

<script>
$(document).ready(function(){
	$('#menu_3').addClass('mui-active');
});
</script>
<script>
$(function() {
	getJsonTop();
	getTradelog();
	allcoin();
});
	
function getJsonTop(){
	$.getJSON("/Ajax/getJsonTop?market={$market}&t=" + Math.random(),function(data){
		if(data){
			if(data['info']['new_price']){
				$('#market_new_price').removeClass('buy');
				$('#market_new_price').removeClass('sell');

				if(data['info']['change'] == 0 || data['info']['change'] > 0){
					$('#market_new_price').addClass('buy');
				}else{
					$('#market_new_price').addClass('sell');
				}

				$("#market_new_price").html(data['info']['new_price']);
				$("title").html(data['info']['new_price'] + " | {$coin_name}-{$coin_type} | {:C('web_title')}");
			}
			if(data['info']['buy_price']){
				$('#market_buy_price').removeClass('buy');
				$('#market_buy_price').removeClass('sell');
				if($("#market_buy_price").html()>data['info']['buy_price']){
					$('#market_buy_price').addClass('sell');
				}
				if($("#market_buy_price").html()<data['info']['buy_price']){
					$('#market_buy_price').addClass('buy');
				}
				$("#market_buy_price").html(data['info']['buy_price']);
				$("#sell_best_price").html('￥'+data['info']['buy_price']);
			}
			if(data['info']['sell_price']){
				$('#market_sell_price').removeClass('buy');
				$('#market_sell_price').removeClass('sell');
				if($("#market_sell_price").html()>data['info']['sell_price']){
					$('#market_sell_price').addClass('sell');
				}
				if($("#market_sell_price").html()<data['info']['sell_price']){
					$('#market_sell_price').addClass('buy');
				}
				$("#market_sell_price").html(data['info']['sell_price']);
				$("#buy_best_price").html('￥'+data['info']['sell_price']);
			}
			if(data['info']['max_price']){
				$("#market_max_price").html(data['info']['max_price']);
			}
			if(data['info']['min_price']){
				$("#market_min_price").html(data['info']['min_price']);
			}
			if(data['info']['volume']){
				if(data['info']['volume']>10000){
					data['info']['volume']=(data['info']['volume']/10000).toFixed(2)+"万"
				}
				if(data['info']['volume']>100000000){
					data['info']['volume']=(data['info']['volume']/100000000).toFixed(2)+"亿"
				}
				$("#market_volume").html(data['info']['volume']);
			}
			if(data['info']['change'] || data['info']['change'] == 0){
				$('#market_change').removeClass('buy');
				$('#market_change').removeClass('sell');

				if(data['info']['change'] == 0){
					$('#market_change').addClass('buy');
					$("#market_change").html("+0.00%");
				}else if(data['info']['change'] > 0){
					$('#market_change').addClass('buy');
					$("#market_change").html('+' + data['info']['change']+"%");
				}else{
					$('#market_change').addClass('sell');
					$("#market_change").html(data['info']['change']+"%");
				}
			}
		}
	});
	setTimeout('getJsonTop()',5000);
}

function allcoin(){
	var trade_qu_id = $('.table-section-title .active').attr('data');
	$.getJSON("/Ajax/getJsonTop2/id/" + trade_qu_id + "?t=" + Math.random(), function (data) {
		if(data){
			var list='';
			for(var i in data['list']){
				ifcolor = (data['list'][i]['change'] >= 0 ? 'red' : 'green');
				
				list+='<li><dl><a href="/Trade/chart/market/'+data['list'][i]['name']+'"><dt class="fl market" style="width: 33%"><i></i><img src="__UPLOAD__/coin/'+data['list'][i]['img']+'" width="20" height="20" alt="" /><span class="coin_name">'+data['list'][i]['coin_name']+'</span></dt><dd class="fl ' + ifcolor + '" style="width: 42%"><i></i>'+data['list'][i]['new_price']+'</dd><dd class="fl tl ' + ifcolor + '" style="width: 25%">' + (parseFloat(data['list'][i]['change']) < 0 ? '' : '+') + ((parseFloat(data['list'][i]['change']) < 0.01 && parseFloat(data['list'][i]['change']) > -0.01) ? "0.00" : (parseFloat(data['list'][i]['change'])).toFixed(2)) + '%<i></i></dd></a></dl></li>';
			}
			$("#all_coin").html(list);
		}
	});
	setTimeout('allcoin()',5000);
}
function trade_qu(o){
	$('.trade_qu_pai').removeClass('active');
	$(o).addClass('active');
	allcoin();
}
</script>
<script type="text/javascript">
function tologin() { window.location.href="{:U('Login/index')}"; }
var market = "{$market}";
var market_round = "{$C['market'][$market]['round']}";//获取交易数量小数点
var market_round_num = "{$C['market'][$market]['round']}";
var market_round_mum = "{$C['market'][$market]['round_mum']}"; //获取交易价小数点	
var market_round_total = parseInt(market_round)+parseInt(market_round_num);
var heh = "{$C['market'][$market]['hou_price']|NumToStr}";
var userid = "{$Think.session.userId}";
var trade_moshi = 1;
var getDepth_tlme = null;
var trans_lock = 0;


// Transaction password setting
function layertpwd(){
    layer.open({
        type: 1,
        title: false,
        closeBtn: 0,
        area: 'autos',
        skin: 'layui-layer-nobg',
        shadeClose: true,
        content: $('#layertpwd')
    });

	$.get('/user/tpwdsetting', function(d){
		if (d==1) { $('#only').prop('checked', true); }
		if (d==2) { $('#every').prop('checked', true); }
		if (d==3) { $('#none').prop('checked', true); }
	})
}

// 最新交易记录
function getTradelog(){
	$.get("/Ajax/getTradelog?market="+market+"&market_round_mum="+market_round_mum+"&market_round="+market_round+"&t="+Math.random()+'&ajax=json',function(data){
		var data = JSON.parse(data);
		if(data){
			if(data['tradelog']){
				var list='';
				var type='';
				var typename='';

				for( var i in data['tradelog']){		
					if(data['tradelog'][i]['type']==1){
						list += '<dd class="red"><span style="width:33%">'+data['tradelog'][i]['addtime']+'</span><span class="tc" style="width:33%">'+(data['tradelog'][i]['price'])+'</span><span class="tr" style="width:33%">'+(data['tradelog'][i]['num'])+'</span></dd>';
					}else{
						list += '<dd class="green"><span style="width:33%">'+data['tradelog'][i]['addtime']+'</span><span class="tc" style="width:33%">'+(data['tradelog'][i]['price'])+'</span><span class="tr" style="width:33%">'+(data['tradelog'][i]['num'])+'</span></dd>';
					}
				}
				$("#orderlist").html(list);
			}
		}
	});
	setTimeout('getTradelog()',5000);
}

// 交易买卖委托信息
function getDepth(){
	$.get("/Ajax/getDepth?market="+market+"&market_round_mum="+market_round_mum+"&market_round="+market_round+"&trade_moshi=99&t="+Math.random()+'&ajax=json',function(data){
		var data = JSON.parse(data);
		if(data){
			if(data['depth']){
				var list = '';
				var sellk = data['depth']['sell'].length;
				if(data['depth']['sell']){
					for(i=0; i<data['depth']['sell'].length; i++){
						list += '<dd><span class="fl">'+(data['depth']['sell'][i][1])+'</span><span class="fr sell">'+(data['depth']['sell'][i][0])+'</span><i class="turntable_bg_green" style="width: '+(data['depth']['sellpbar'][i])+'%"></i></dd>';
					}
				}
				$("#selllist").html(list);
				list = '';
				if(data['depth']['buy']){
					for(i=0; i<data['depth']['buy'].length; i++){
						list += '<dd><span class="fl buy">'+(data['depth']['buy'][i][0])+'</span><span class="fr">'+(data['depth']['buy'][i][1])+'</span><i class="turntable_bg_red" style="width: '+(data['depth']['buypbar'][i])+'%"></i></dd>';
					}
				}
				$("#buylist").html(list);
			}
		}
	});
	clearInterval(getDepth_tlme);

	var wait=second=1;
	getDepth_tlme=setInterval(function(){
		wait--;
		if(wait<0){
			clearInterval(getDepth_tlme);
			getDepth();
			wait=second;
		}
	},1000);
}

function closetanchu(){
	layer.closeAll('loading');
}

		
// 执行函数
$(function(){
	getJsonTop();
	getDepth();
	xianshi();
});
	
function xianshi(){
	$('#market_change1').html(heh.toFixed(market_round_num))
}
	
function toNum(num,round){
	var mum=Math.round(num*Math.pow(10,round))/Math.pow(10,round);
	if(mum<0){var mum=0;}
	return mum;
}


//过滤HTML标签
function removeHTMLTag(str) {
	str = str.replace(/<\/?[^>]*>/g, ''); //去除HTML tag
	str = str.replace(/[ | ]*\n/g, '\n'); //去除行尾空白
	//str = str.replace(/\n[\s| | ]*\r/g,'\n'); //去除多余空行
	str = str.replace(/ /ig, ''); //去掉 
	return str;
}
</script>
<include file="Public:footer" />
</body>
</html>